package com.springboot.transactional.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.springboot.transactional.dao.AccountMapper;

@Service
public class AccountService {
	private AccountMapper accountMapper;

	@Autowired
	public void setAccountMapper(AccountMapper accountMapper) {
		this.accountMapper = accountMapper;
	}

	public int update(String name, double money, int id) {
		return accountMapper.update(name, money, id);
	}

	@Transactional
	public void transfer() throws RuntimeException {
		accountMapper.update("a", 90, 1);// 用户1减10块 用户2加10块
		int i = 1 / 0;
		accountMapper.update("b", 110, 2);
	}

}
